package com.example.fileserver.entity;

import lombok.*;

/**
 * @author yousj
 */
@Getter
@ToString
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class R<T> {

    private int code;

    private String message;

    private T data;

    private static <T> R<T> of(int code, String message, T data) {
        return new R<>(code, message, data);
    }

    public static <T> R<T> isOk(T data) {
        return of(ResConst.OK.getCode(), ResConst.OK.getMessage(), data);
    }

    public static <T> R<T> isOk(T data, String message) {
        return of(ResConst.OK.getCode(), message, data);
    }

    public static <T> R<T> isOk() {
        return of(ResConst.OK.getCode(), ResConst.OK.getMessage(), null);
    }

    public static <T> R<T> isFail(ResConst resp) {
        return of(resp.getCode(), resp.getMessage(), null);
    }

    public static <T> R<T> isFail(ResConst resp, String message) {
        return of(resp.getCode(), message, null);
    }


}
